/**
 * Labox有限公司项目InnovationServer
 * Labox版权所有 @copyright 2009
 * @javaclass LoginPacketHandler.java @author 丁宁 @time 2009-11-27
 */
package labox.innovation.loginserver.http;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Executor;

import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

/**
 * @author Administrator
 *
 */
public abstract class AbstractHttpServer {

	private HttpServer hs;

	public AbstractHttpServer(InetAddress address, int tcpPort, HttpHandler handler, String context, Executor exe) throws IOException {

		InetSocketAddress iaddress = null;
		if (address == null)
			iaddress = new InetSocketAddress(tcpPort);
		else
			iaddress = new InetSocketAddress(address, tcpPort);
		hs = HttpServer.create(iaddress, 20);

		hs.createContext(context, handler);
		hs.setExecutor(exe);

	}

	public void stop() {
		hs.stop(10);
	}

	public void start() {
		hs.start();
	}
}
